package com.ltg.urban.domain.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ltg.framework.util.http.PageInfo;
import com.ltg.framework.util.http.Result;
import com.ltg.urban.domain.sys.data.request.ModifyMenuReq;
import com.ltg.urban.domain.sys.entity.SysMenu;
import com.ltg.urban.domain.sys.entity.SysUser;
import com.ltg.urban.domain.sys.mapper.SysMenuMapper;
import com.ltg.urban.domain.sys.service.SysMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p> ClassName: SysMenuServiceImpl </p>
 * <p> Package: com.ltg.urban.domain.sys.service.impl </p>
 * <p> Description: </p>
 * <p></p>
 *
 * @Author: LTG
 * @Create: 2023/2/24 - 11:40
 * @Version: v1.0
 */
@Service
@RequiredArgsConstructor
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    private final SysMenuMapper sysMenuMapper;

    @Override
    public PageInfo<SysMenu> pageLis(Page<SysMenu> page) {
        LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
        Page<SysMenu> sysMenuPage = sysMenuMapper.selectPage(page, wrapper);
        return new PageInfo<>(sysMenuPage);
    }

    @Override
    public Result<SysMenu> create(ModifyMenuReq req) {
        SysMenu sysMenu = SysMenu.builder()
                .menuName(req.getMenuName())
                .path(req.getPath())
                .build();
        sysMenuMapper.insert(sysMenu);
        return Result.success(sysMenu);
    }

    @Override
    public Result<SysMenu> modify(String menuId, ModifyMenuReq req) {
        SysMenu sysMenu = sysMenuMapper.selectById(menuId);
        sysMenu.setMenuName(req.getMenuName());
        sysMenu.setPath(req.getPath());
        sysMenuMapper.updateById(sysMenu);
        return Result.success(sysMenu);
    }
}
